package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.IncomePartJudgeVo;
import com.koocloud.electroplatemanage.service.DrawNoService;
import com.koocloud.electroplatemanage.service.IncomePartJudgeService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.List;
/**
 * @program: electroplatemanage
 * @description: 来料接收与判定控制层
 * @author: zww
 * @create: 2020-10-08 12:28
 */
@RestController
@RequestMapping("/incomepartjudge")
public class IncomePartJudgeController {
    static Logger log = Logger.getLogger("incomepartjudge");
    @Autowired
    IncomePartJudgeService incomePartJudgeService;
    @Autowired
    DrawNoService drawNoService;



    /**
     * @Description:来料主表的总查询查询接口
     * @Param:   暂时无
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate  包含两个数组
     * 先获取已生效的副表字段，拼接主表字段，得到总字段作为查询接口的第一个数组返回将数组的每一列用LinkedHashMap拿到对应的数据，作为第二个数组
     * @Author: yxx
     * @date: 2020/10/8
     */
    @RequestMapping(value = "/selectTotalIncomepartjudge", method = RequestMethod.POST, name = "分页查询")
    public ResponseTemplate selectTotalIncomepartjudge() {

        //先获取已生效的副表字段，拼接主表字段，得到总字段作为查询接口的第一个数组返回将数组的每一列用LinkedHashMap拿到对应的数据，作为第二个数组
        return incomePartJudgeService.selectTotalIncomepartjudge();
    }



    /**
     * @Description:通过pk查询来料接收与判定表一条记录
     * @Param: [orderNumber]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/10/8
     */
    @RequestMapping(value = "/selectByPk", method = RequestMethod.POST, name = "主键查询")
    public ResponseTemplate selectByPk(@RequestParam(name="id") String id) {
        //通过pk查询来料接收与判定表的一条记录
        return incomePartJudgeService.selectByPk(id);
    }

    /**
     * @Description: 查询所有记录 分页   订单号/来件单位/图号(参照图号表)
     * @Param: [page,limit, orderNumber/incomePartUnit/pkDrawNo]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/10/8
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(@RequestParam(value = "page") String page,@RequestParam(value = "limit") String limit,@RequestParam(value = "beginTime")String beginTime,@RequestParam(value = "endTime")String endTime,@RequestParam(value = "idOrName")String idOrName) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }


        //查询所有记录 分页
        return incomePartJudgeService.selectAllData(page,limit,beginTime,endTime,idOrName);
    }


    /**
     * @Description: 查询所有记录 不分页   订单号/来件单位/图号(参照图号表)
     * @Param: [page,limit, orderNumber/incomePartUnit/pkDrawNo]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/10/8
     */
    @RequestMapping(value = "/selectAllDataTwo", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllDataTwo() {

        //查询所有记录 分页
        return incomePartJudgeService.selectAllDataTwo();
    }

    /**
     *@Description:查询所有非权限数据
     *@Param: [page, limit, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/26
     */
    @RequestMapping(value = "/selectAllNotAuthData", method = RequestMethod.POST, name = "查询非权限所有数据")
    public ResponseTemplate selectAllNotAuthData(@RequestParam(value = "page") String page,@RequestParam(value = "limit") String limit,@RequestParam(value = "beginTime")String beginTime,@RequestParam(value = "endTime")String endTime,@RequestParam(value = "idOrName")String idOrName) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return incomePartJudgeService.selectAllNotAuthData(page,limit,beginTime,endTime,idOrName);
    }
    /**
     *@Description:插入一条记录
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/8
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(HttpServletRequest request,@RequestBody IncomePartJudgeVo incomePartJudgeVo) {
        String userId = request.getHeader("userId");
        incomePartJudgeVo.setCreator(userId);
        //插入一条记录
        return incomePartJudgeService.insert(incomePartJudgeVo);
    }
    /**
     *@Description:批量插入记录
     *@Param: [listIncomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/8
     */
    @RequestMapping(value = "/batchInsert", method = RequestMethod.POST, name = "批量新增数据")
    public ResponseTemplate batchInsert(@RequestBody List<IncomePartJudgeVo> listIncomePartJudgeVo) {
        //批量插入记录
        return incomePartJudgeService.batchInsert(listIncomePartJudgeVo);
    }
    /**
     *@Description:逻辑删除一条记录
     *@Param: [orderNumber]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/8
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(HttpServletRequest request, @RequestParam(name="id") String id) {
        //逻辑删除一条记录
        String userId = request.getHeader("userId");
        return incomePartJudgeService.delete(id,userId);
    }
    /**
     *@Description:通过pks批量逻辑删除记录
     *@Param: [listPks]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/8
     */
    @RequestMapping(value = "/batchDeleteByPks", method = RequestMethod.POST, name = "批量逻辑删除记录")
    public ResponseTemplate batchDeleteByPks(@RequestBody List<String> listPks) {
        //通过pks批量逻辑删除记录
        return incomePartJudgeService.batchDeleteByPks(listPks);
    }
    /**
     *@Description:修改一条记录
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/9
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(HttpServletRequest request, @RequestBody IncomePartJudgeVo incomePartJudgeVo) {
        String userId = request.getHeader("userId");
        incomePartJudgeVo.setModifier(userId);
        //修改一条记录
        return incomePartJudgeService.update(incomePartJudgeVo);
    }

    /**
     *@Description:获取订单号
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/14
     */
    @RequestMapping(value = "/getIncomePartJudgeOrderNo", method = RequestMethod.POST, name = "获取订单号")
    public ResponseTemplate getIncomePartJudgeOrderNo() {

        //修改一条记录
        return incomePartJudgeService.getIncomePartJudgeOrderNo();
    }

    /**
     *@Description: 获取序
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/9
     */
    @RequestMapping(value = "/getId", method = RequestMethod.POST, name = "获取序")
    public ResponseTemplate getId() {

        //修改一条记录
        return incomePartJudgeService.getId();
    }

    /**
     *@Description:获取含税单价
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/14
     */
    @RequestMapping(value = "/getIncomePartJudgeUnitPrice", method = RequestMethod.POST, name = "获取含税单价")
    public ResponseTemplate getIncomePartJudgeUnitPrice(String drawNoCode) {

        //获取含税单价
        return incomePartJudgeService.getIncomePartJudgeUnitPrice(drawNoCode);
    }

    /**
     *@Description: 获取现有的所有图号
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @RequestMapping(value = "/selectDrawNo", method = RequestMethod.POST, name = "获取现有的所有图号")
    public ResponseTemplate selectDrawNo(String idOrName){
        return drawNoService.selectDrawNo(idOrName);
    }

    /**
     *@Description: 获取含税总价
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @RequestMapping(value = "/getIncomePartJudgeUnitTotalPrice", method = RequestMethod.POST, name = "获取含税总价")
    public ResponseTemplate getIncomePartJudgeUnitTotalPrice(@RequestBody IncomePartJudgeVo incomePartJudgeVo) {

        //获取含税总价
        return incomePartJudgeService.getIncomePartJudgeUnitTotalPrice(incomePartJudgeVo);
    }

    /**
     *@Description: 获取工时
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @RequestMapping(value = "/getIncomePartJudgeUnitWorkTime", method = RequestMethod.POST, name = "获取工时")
    public ResponseTemplate getIncomePartJudgeUnitWorkTime(@RequestBody IncomePartJudgeVo incomePartJudgeVo){
        return incomePartJudgeService.getIncomePartJudgeUnitWorkTime(incomePartJudgeVo);

    }
    /**
     *@Description: 获取总工时
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @RequestMapping(value = "/getIncomePartJudgeUnitTotalWorkTime", method = RequestMethod.POST, name = "获取总工时")
    public ResponseTemplate getIncomePartJudgeUnitTotalWorkTime(@RequestBody IncomePartJudgeVo incomePartJudgeVo) {

        //获取含税总价
        return incomePartJudgeService.getIncomePartJudgeUnitTotalWorkTime(incomePartJudgeVo);
    }

    /**
     *@Description: 获取前端表头信息
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/21
     */
    @RequestMapping(value = "/getIncomePartField", method = RequestMethod.POST, name = "获取前端表头信息")
    public ResponseTemplate getIncomePartField() {

        //获取前端表头信息
        return incomePartJudgeService.getIncomePartField();
    }

    /**
     *@Description: excel数据导入@RequestParam(name="id") String id,@RequestParam("file") MultipartFile files
     *@Param: [files]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/26
     */
    @RequestMapping(value = "/getExcelImport", method = RequestMethod.POST, name = "excel数据导入")
    public ResponseTemplate getExcelImport(HttpServletRequest request, @RequestParam("file") MultipartFile files){
        String file1 = files.getOriginalFilename();
        String path = System.getProperty("user.dir");
        try {
            BufferedOutputStream stream = null;
            path = System.getProperty("user.dir");
            byte[] bytes = files.getBytes();
            stream = new BufferedOutputStream(new FileOutputStream(new File(path+ File.separator + file1)));
            stream.write(bytes);
            stream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        String file = path + File.separator +file1;
        String id  = "3";//request.getHeader("userId");
        // excel数据导入
        return incomePartJudgeService.getExcelImport(id,file);
    }

    /**
     *@Description: 来料信息确认
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/18
     */
    @RequestMapping(value = "/confirmEntryInfo", method = RequestMethod.POST, name = "来料信息确认")
    public ResponseTemplate confirmEntryInfo(HttpServletRequest request,String workOrderNumber){
        String id  = request.getHeader("userId");
        return incomePartJudgeService.confirmEntryInfo(workOrderNumber,id);

    }
    /**
     *@Description:工艺卡片打印查询
     *@Param: [page, limit, beginTime, endTime, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/25
     */
    @RequestMapping(value = "/selectProcessCardPrinting", method = RequestMethod.POST, name = "工艺卡片打印查询")
    public ResponseTemplate selectProcessCardPrinting(@RequestParam(value = "page") String page,@RequestParam(value = "limit") String limit,@RequestParam(value = "beginTime")String beginTime,@RequestParam(value = "endTime")String endTime,@RequestParam(value = "idOrName")String idOrName){
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }

        return incomePartJudgeService.selectProcessCardPrinting(page,limit,beginTime,endTime,idOrName);
    }


}